package ls.vuecp.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JSplitPane;

import ls.vuecp.gui.component.LWMap;
import ls.vuecp.gui.toolbar.VueToolbarController;
import ls.vuecp.gui.view.MapViewer;

public class GuiComponents 
{
	private static GuiComponents mthis = null;
	public static GuiComponents getGuiComponents(){ if(mthis==null) new GuiComponents(); return mthis; }
	
	
	public GuiComponents()
	{
		mthis = this;
	}
	
	// components;
	public MapTabbedPane mMapTabsLeft;
	public MapTabbedPane mMapTabsRight;
	
	public JSplitPane mViewerSplit;
	public VueFrame mframe;
	public VueMenuBar mmb;
	public VueToolbarController mtbc;
	
	public MapViewer leftViewer;
	public MapViewer rightViewer;
	public LWMap leftMap;
	public LWMap rightMap;
	//
	public void init()
	{
		createComponent();
		setLayout();
		show();	
	}

	public void createComponent()
	{
		leftMap = new LWMap();
		leftMap.setLabel("LEFT");
		rightMap = new LWMap();
		rightMap.setLabel("right");
		
		leftViewer = new MapViewer("*LEFT");
        rightViewer = new MapViewer("right");
        leftViewer.setFocusable(false);
        rightViewer.setFocusable(false);
				
		mMapTabsLeft = new MapTabbedPane("*left", true);
		mMapTabsRight = new MapTabbedPane("right", false);
		
		mViewerSplit = new JSplitPane();
		mViewerSplit.setName("splitPane");
		mViewerSplit.setResizeWeight(0.5d);
		mViewerSplit.setOneTouchExpandable(true);
		mViewerSplit.setDividerLocation(0.3);
		mViewerSplit.setContinuousLayout(true);
		
		mframe = VueFrame.getVueFrame();
		
		mtbc = VueToolbarController.getController();
		mtbc.buildToolbar();
		
		mmb = VueMenuBar.getVueMenuBar();
		mmb.buildMenu();
		
	}
	public void setLayout()
	{
		leftViewer.addMap(leftMap);
		rightViewer.addMap(rightMap);
		
		mMapTabsLeft.addViewer(leftViewer);
        mMapTabsRight.addViewer(rightViewer);
        
		mViewerSplit.setRightComponent(mMapTabsRight);
		mViewerSplit.setLeftComponent(mMapTabsLeft);
		
		//mframe.addComp(mtbc.getToolbarPanel(), BorderLayout.NORTH);
		mframe.setJMenuBar(mmb);
		mframe.addComp(mViewerSplit, BorderLayout.CENTER);
		
		mframe.addComp(mtbc.getToolbarPanel(), BorderLayout.NORTH);
	}
	
	void show()
	{
		mframe.validate();
		mframe.setSize(new Dimension(1024,768));
		mframe.setLocation(200,200);
		
		mframe.setVisible(true);
	}
}
